package shipNuking;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client extends Player {
	
	Socket sock;
	private int[][] localHits = new int[10][10]; 		// save hits and Ships also on the client. 
	private Ship[][] localShips = new Ship[10][10];		// don't need to transport the whole 
	private int[][] localHitsServer = new int[10][10]; 	// array from the server to client after 
														// every shot
	
	public Client(String Ip){
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j <= 9; j++) {
				this.localHits[i][j] = 0;
			}
		}
		try {
			this.sock = new Socket(Ip, 6666);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void setShip(int x1, int y1, int x2, int y2, Ship z){
		this.placeShip(x1, y1, x2, y2, z, this.localShips);
	}
	
	public boolean getShip(int x, int y){
		return (this.localShips[x][y] == null);
	}
	public void setField(int x, int y, int value){
		this.localHits[x][y] = value;
	}
	
	public int getField(int x, int y){
		return this.localHits[x][y];
	}
	
	public void setFieldServer(int x, int y, int value){
		this.localHitsServer[x][y] = value;
	}
	
	public int getFieldServer(int x, int y){
		return this.localHitsServer[x][y];
	}
	
	public Socket getSock(){
		return this.sock;
	}
	
	public void setSock(String Ip){
		try {
			this.sock = new Socket(Ip, 6666);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
